import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class DynamicProxy {
    public static void main(String[] args) {
        DAD d1 = new DAD();
        MM1 o = (MM1) MyProxy.gMyproxyIns(d1);
        o.move(7);
        String this_is_cool = o.think("this is cool");
        System.out.println(this_is_cool);
        Solider solider = new Solider();
        Sport s1  = (Sport) MyProxy.gMyproxyIns(solider);
        s1.Move();
    }
}

interface MM1 {
    boolean alive = false;

    void move(int i);

    String think(String st);

    void Dead();
}

class DAD implements MM1 {

    @Override
    public void move(int i) {
        System.out.println("move " + i + " steps");
    }

    @Override
    public String think(String st) {
        String thought = st;
        return "I'm thinking that " + thought;
    }

    @Override
    public void Dead() {
        System.out.println(!alive);
    }
}

class MyProxy {
    public static Object gMyproxyIns(Object obj) {
        MyInvokations MI = new MyInvokations();
        MI.Select(obj);
        return Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), MI);
    }
}


class MyInvokations implements InvocationHandler {
    private Object obj;

    public void Select(Object obj) {
        this.obj = obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        Object invoke = method.invoke(obj, args);
        return invoke;
    }


}